package org.ewaf.framework.ibatis.type;

import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Date;

import org.ewaf.framework.util.DateUtil;

import com.ibatis.sqlmap.client.extensions.ParameterSetter;
import com.ibatis.sqlmap.client.extensions.ResultGetter;
import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;

public class DateOnlyTypeHanlderCallback implements TypeHandlerCallback {

	public Object getResult(ResultGetter arg0) throws SQLException {
		return new UnsupportedOperationException();
	}

	public void setParameter(ParameterSetter setter, Object parameter)
			throws SQLException {
		
		if (parameter == null) {
			setter.setNull(Types.TIMESTAMP);
		} else {
			Date date = DateUtil.dateOnly((Date) parameter);
			setter.setTimestamp(new Timestamp(date.getTime()));
		}
	}

	public Object valueOf(String s) {
		return s;
	}

}
